package com.lei.tong.db;


import com.lei.tong.bean.StudentBean;
import com.lei.tong.log_utlis.LogUtils;

import java.util.List;

public class DbHelper {
    public static boolean insert(StudentBean studentBean){
        if (studentBean == null)return false;
        StudentBeanDao studentBeanDao = DbManger.getInstance().getDaoSession().getStudentBeanDao();
        try {
            long index = studentBeanDao.insertOrReplace(studentBean);
            LogUtils.e("id"+index);
            return true;
        }catch (Exception e){
            return false;
        }
    }
    public static List<StudentBean> query(){
        StudentBeanDao studentBeanDao = DbManger.getInstance().getDaoSession().getStudentBeanDao();
        try {
            return studentBeanDao.loadAll();
        }catch (Exception e){
            return null;
        }
    }
    public static void delete(String index){
        if (index!=null){
            try {
                StudentBeanDao studentBeanDao = DbManger.getInstance().getDaoSession().getStudentBeanDao();
                studentBeanDao.deleteByKey(Long.valueOf(index));
                LogUtils.e("删除成功");
            }catch (Exception e){
                LogUtils.e("删除失败");
            }
        }else {
            LogUtils.e("输入为空");
        }
    }
    public static void update(String id){
            if (!id.equals("")){
                Long a = Long.parseLong(id);
                StudentBeanDao studentBeanDao = DbManger.getInstance().getDaoSession().getStudentBeanDao();
                StudentBean bean = new StudentBean(a,"徐狗","123645");
                studentBeanDao.update(bean);
                LogUtils.e("修改成功");
            }else {
                LogUtils.e("输入为空，无法修改");
            }
    }
}
